home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / gag / WaveBench.lha / WaveBench / Wavebench.c < prev    next >
C/C++ Source or Header  |  1987-11-15  |  7KB  |  214 lines

  1.  
  2. /*
  3.  * Wavebench.  A display hack & BKDC (Badge Killer Demo Contest) entry by
  4.  * Bryce Nesbitt.  Subtitled, "The Deadline is _WHEN???_"
  5.  *
  6.  * "In the grand tradition of 'Viacom' this display hack is for people
  7.  * who wish to get seasick while using the Amiga."
  8.  *
  9.  * Tested to compile without warnings under Lattice 3.03, Lattice 3.10 and
  10.  * Manx 3.4b compilers.  Lattice 4.0 will be the next compiler to try out.
  11.  * I'm new to this cross compiler stuff, hope its ok.  (Would you believe
  12.  * it is smaller under Lattice 3.03 than Manx 3.4b??  Wierd, but true)
  13.  *
  14.  * Not guaranteed to work on any future versions of the Amiga computer.
  15.  * It is almost guarnteed to fail on an MMU version of the Amiga.
  16.  *
  17.  * Try it before you read the technical desciption at the end of this file,
  18.  * it's more fun that way.
  19.  *
  20.  * Bryce Nesbitt, 1712 Marin Ave., Berkeley, Ca 94707-2206
  21.  * bryce@hoser.berkeley.EDU -or- ucbvax!hoser!bryce
  22.  * bryce@cogsci.berkeley.EDU -or- ucbvax!cogsci!bryce
  23.  */
  24.  
  25. #define SCAN_FACTOR 8L        /* Change this to change the effect */
  26. #undef    DEBUG
  27.  
  28. #include <exec/types.h>
  29. #include <exec/memory.h>
  30. #include <libraries/dos.h>
  31. #include <libraries/dosextens.h>
  32. #include <intuition/intuition.h>
  33. #include <intuition/intuitionbase.h>
  34. #include <hardware/custom.h>
  35. #include <graphics/gfxbase.h>
  36. #include <graphics/gfxmacros.h>
  37. #include <functions.h>
  38.  
  39.        struct IntuitionBase    *IntuitionBase;
  40.        struct GfxBase           *GfxBase;
  41.        struct Window           *MyWindowP;
  42.        struct Screen           *MyScreenP;
  43.        struct ViewPort           *MyViewPortP;
  44.        struct View           *MyViewP;
  45.        struct UCopList           *MyUCopListP;
  46.        struct Process           *MyProcessP;
  47.        long            wsignals; /* What signals to exit on */
  48.        long            key;      /* LockIBase() key */
  49.  
  50. struct NewWindow MyWindow=
  51.     {
  52.     0,11,395,10,    /* Don't obscure drag bar, please! */
  53.     3,1,
  54.     CLOSEWINDOW,
  55.     WINDOWCLOSE|SIMPLE_REFRESH|NOCAREREFRESH|WINDOWDRAG|WINDOWDEPTH,
  56.     0,0,         /* Don't forget NOCAREREFRESH if you don't    */
  57.             /* handle type REFRESHWINDOW IntuiMessages!   */
  58.            /* ACTIVATE is *not* set, since this window     */
  59.           /* can't do anything with the keyboard anyway */
  60.     (UBYTE *)"Wavebench by Bryce Nesbitt",
  61.     0,0,
  62.     1,1,-1,-1,         /* Set maximum window sizes to -1,-1 for */
  63.             /* for people with big-screen displays   */
  64.     WBENCHSCREEN,
  65.     };
  66.  
  67.  
  68.  
  69. cleanexit(number,dos_code)
  70. int  number;
  71. long dos_code;
  72. {
  73.     if (MyWindowP)    CloseWindow (MyWindowP);
  74.     if (GfxBase)    CloseLibrary(GfxBase);
  75.     if (IntuitionBase)    CloseLibrary(IntuitionBase);
  76.     MyProcessP->pr_Result2=dos_code;    /* Set secondary "why" result code */
  77.     exit(number);
  78. }
  79.  
  80.  
  81. /* Set up the user copper list ready to be mangled by the animator portions
  82.  * of the program.  Some wrinkles are needed to work for interlaced screens
  83.  */
  84. setclist()
  85. {
  86. long counter;
  87.  
  88.     key=LockIBase(0L);
  89.     if (MyViewPortP->UCopIns)
  90.     { UnlockIBase(key); return(0); }
  91.     MyUCopListP=(struct UCopList *)AllocMem(12L,MEMF_CLEAR+MEMF_PUBLIC);
  92.     /* This allocates the UCopList structure.  The system will be
  93.        responsible for deallocating it.  */
  94.  
  95.     CINIT( MyUCopListP,(MyScreenP->Height/SCAN_FACTOR<<2L)+2L );
  96.     /* The manuals say that CINIT will allocate a UCopList if passed
  97.        a zero.    This feature does not work, thus the AllocMem() */
  98.  
  99. #ifdef DEBUG
  100.     printf("# copper instructions is %d\n",(MyScreenP->Height/SCAN_FACTOR<<2L)+2L );
  101. #endif DEBUG
  102.  
  103.     for (counter=0; counter < MyScreenP->Height; counter+=SCAN_FACTOR)
  104.     {
  105.     CWait(MyUCopListP,counter,17L);   /* 15 is the start of h. blanking */
  106.     CBump(MyUCopListP);
  107.     CMove(MyUCopListP,0xDFF102L,counter&6L);
  108.     CBump(MyUCopListP);
  109.     }
  110.     CEND (MyUCopListP);
  111.     MyViewPortP->UCopIns=MyUCopListP;
  112.     UnlockIBase(key);
  113.  
  114.     MakeScreen(MyScreenP);
  115.     RethinkDisplay();
  116.     return(1);
  117. }
  118.  
  119.  
  120.  
  121. main()
  122. {
  123. struct CopList *TempDspIns;
  124. struct CopList *TempSprIns;
  125. struct CopList *TempClrIns;
  126.  
  127.     MyProcessP=(struct Process *)FindTask(0L);
  128.  
  129.     /* Open libraries with 0L, indicating any version is ok */
  130.     if (!( IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0L) ))
  131.     cleanexit(21,0L);
  132.     if (!( GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",0L) ))
  133.     cleanexit(22,0L);
  134.     if (!( MyWindowP=(struct Window *)OpenWindow(&MyWindow) ))
  135.     cleanexit(23,ERROR_NO_FREE_STORE);
  136.     wsignals    = (1L<<MyWindowP->UserPort->mp_SigBit) | SIGBREAKF_CTRL_C;
  137.  
  138.     if ( GfxBase->LibNode.lib_Version < 33 )
  139.     {                /* If older than Kickstart V1.2... */
  140.     SetWindowTitles(MyWindowP,"Error: Requires Kickstart V1.2!",-1L);
  141.     Wait (wsignals);
  142.     cleanexit(5);
  143.     }
  144.     if ( AvailMem(MEMF_CHIP)<4096L )
  145.     {
  146.     SetWindowTitles(MyWindowP,"Error: Out of chip memory!",-1L);
  147.     Wait (wsignals);
  148.     cleanexit(24,ERROR_NO_FREE_STORE);
  149.     }
  150.  
  151.     /* The Workbench screen can't close while our window is open! */
  152.  
  153.     MyScreenP    =MyWindowP->WScreen;
  154.     MyViewP    =(struct View *)ViewAddress();
  155.     MyViewPortP =(struct ViewPort *)ViewPortAddress(MyWindowP);
  156.  
  157.     if (!setclist())        /* set up a user copper list on the workbench */
  158.     {
  159.     SetWindowTitles(MyWindowP,"Error: User copperlist in use!",-1L);
  160.     Wait (wsignals);
  161.     cleanexit(5);
  162.     }
  163. #ifdef DEBUG
  164.     printf("\nWindow %lx, Screen %lx, hieght %lx\n",MyWindowP,MyScreenP,(long)MyScreenP->Height);
  165. #endif DEBUG
  166.  
  167.     SetTaskPri(FindTask(0L),50L);   /* Bump our priority to 50 */
  168.     manglecop(wsignals,MyViewP,GfxBase);
  169.     SetTaskPri(FindTask(0L),0L);    /* Be nice, set our priority back */
  170.  
  171.     key=LockIBase(0L);    /* Deallocate only the UCopList we added */
  172.     TempDspIns=MyViewPortP->DspIns;
  173.     TempSprIns=MyViewPortP->SprIns;
  174.     TempClrIns=MyViewPortP->ClrIns; /* Did I hear "register coloring?" :-) */
  175.     TempDspIns=TempSprIns=TempClrIns=0;
  176.     FreeVPortCopLists(MyViewPortP);  /* Deallocates the UCopList   */
  177.                     /* and all that hangs from it */
  178.     MyViewPortP->DspIns=TempDspIns;
  179.     MyViewPortP->SprIns=TempSprIns;
  180.     MyViewPortP->ClrIns=TempClrIns;
  181.     UnlockIBase(key);
  182.  
  183.     MakeScreen(MyScreenP);
  184.     RethinkDisplay();
  185.     cleanexit(0);
  186. }
  187.  
  188. /*
  189.  * Technical description:
  190.  *
  191.  * The graphics co-processor (copper) is used to shift the horizontal
  192.  * fine scroll bits on the specified scan lines.  This pattern is
  193.  * rotated in a wave.  The range of these registers is 16 low resolution
  194.  * pixels (32 high res).  The choice of the number of scan lines between
  195.  * iterations is arbitrary, and may be as little as 1. (however there is
  196.  * a benign bug in graphics that shows up with real low numbers)
  197.  * The processor speed is not slowed down too much... dragging
  198.  * screens, however, is. (Can you say "MrgCop()"?)
  199.  *
  200.  * The pointer sprite is not affected, since sprites have their own
  201.  * independent scroll registers.
  202.  *
  203.  * This program must be considered "dirty" since it animates the copper list
  204.  * itself (instead of using the hardware independent CINIT,CWAIT,CMOVE
  205.  * facilities).  In general mucking with other people's screens is a rude
  206.  * thing to do anyway.
  207.  *
  208.  * The program can be modified to affect any screen... but what if that
  209.  * screen closes mid mangle?  Think about these things, please.
  210.  *
  211.  * The program is nice about telling the user that it requires Kickstart
  212.  * V1.2, if started under an earlier version.
  213.  */
  214.